package com.woniuxy.controller;



import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.entity.Book;
import com.woniuxy.entity.Borrow;
import com.woniuxy.entity.User;
import com.woniuxy.service.BorrowService;

@Controller
@RequestMapping("/borrow")
public class BorrowController {

	@Autowired
	BorrowService borrowService;
	
	
	@RequestMapping("/borrow")
	@ResponseBody
	public String borrow(@RequestParam("bid") int bid,HttpServletRequest request) {
		User user=(User) request.getSession().getAttribute("user");
		//System.out.println(user);
		//System.out.println(bid);
		//System.out.println(bid);
		//System.out.println(user.getUid());
		String result=borrowService.borrow(bid,new Date(),1,user.getUid());
		System.out.println(result);
		return result;
		//return result;
	}
	
	@RequestMapping("/return")
	@ResponseBody
	public String returnBook(@RequestParam("bid") int bid,HttpServletRequest request) {
		User user=(User) request.getSession().getAttribute("user");
		//System.out.println(user);
		//System.out.println(bid);
		String result=borrowService.updateBookFlagByBid(bid, 0,user.getUid());
		return result;
	}
	
	@RequestMapping("list")
	@ResponseBody
	public List<Borrow> seleceAllBorrow(){
		List<Borrow> listborrow=borrowService.selceAllBorrow();
		System.out.println(listborrow);
		return listborrow;
	}
	
}
